<?php
/**
 * Created by PhpStorm.
 * User: Hong
 * Date: 2018/3/12
 * Time: 11:35
 * Function:
 */

namespace Organize\Controllers\Leaders;


use Organize\Controllers\BaseOrganizeController;
use Platform\Models\Organize\LeaderPermission;
use Platform\Repository\Organize\LeaderRepository;
use Platform\System\Tools\Permission\OrganizeImporter;
use Platform\System\Tools\ResultTool;

/**
 * @module 权限管理
 *
 * Class PermissionController
 * @namespace Admin\Controllers\System
 */
class PermissionController extends BaseOrganizeController
{
    /**
     * @var OrganizeImporter
     */
    protected $importer;

    /**
     * @var LeaderRepository
     */
    protected $repository;

    /**
     * PermissionController constructor.
     * @param OrganizeImporter $importer
     * @param  LeaderRepository $repository
     */
    public function __construct(OrganizeImporter $importer, LeaderRepository $repository)
    {
        parent::__construct();
        $this->importer = $importer;
        $this->repository = $repository;
    }

    /**
     * @permission 权限列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $permissions = LeaderPermission::get(['id','name','module']);
        $data = LeaderPermission::makeData($permissions);
        return myResult()->setData($data)->send();
    }

    /**
     * @permission 导入权限
     * @return \Illuminate\Http\JsonResponse
     * @throws \ReflectionException
     */
    public function import()
    {
        $this->importer->handle($this->auth_type);
        LeaderPermission::refreshCache();
        return myResult()->setCode(ResultTool::CODE_SUCCESS,'导入完成')->send();
    }

}